package com.hh.game.service.gateway.utils;

import io.netty.channel.ChannelHandlerContext;

import java.net.SocketAddress;

public class IpUtil {

    public static String getIp(SocketAddress address){
        String ip = null;
        if (address != null) {
            ip = address.toString().split(":")[0];
        }
        if(ip.startsWith("/")){
            ip = ip.substring(1);
        }
        return ip;
    }

    public static String getIp(ChannelHandlerContext ctx){
        return getIp(ctx.channel().remoteAddress());
    }
}
